package com.ggh.jinjilive.ui.mine.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemMineDealDetailBinding;
import com.ggh.jinjilive.databinding.ItemMineDetailBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.mine.DiamondMobile;

import java.util.List;

public class MineDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<DiamondMobile> diamondMobileList;

    public void setAdd(List<DiamondMobile> diamondMobileList) {
        this.diamondMobileList = diamondMobileList;
        notifyDataSetChanged();
    }

    public void Add(List<DiamondMobile> diamondMobileList) {
        if(null != this.diamondMobileList){
            this.diamondMobileList.addAll(diamondMobileList);
        }else {
            this.diamondMobileList = diamondMobileList;
        }
        notifyDataSetChanged();
    }



    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemMineDetailBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_mine_detail, parent, false);
        return new ItemViewHolder(binding);
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
        DiamondMobile diamondMobile = diamondMobileList.get(position);
        ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
        if(null != diamondMobile){
            if(TextUtils.isEmpty(diamondMobile.getTotal_price())){
                holder.binding.detailLeftItem1.setText(diamondMobile.getStart_time());
            }else {
                holder.binding.detailLeftItem1.setText(diamondMobile.getTotal_price());
            }
            if(TextUtils.isEmpty(diamondMobile.getNumber())){
                holder.binding.detailLeftItem2.setText(diamondMobile.getEnd_time());
            }else {
                holder.binding.detailLeftItem2.setText(diamondMobile.getNumber());
            }
            if(TextUtils.isEmpty(diamondMobile.getNickname())){
                holder.binding.detailLeftItem3.setText(diamondMobile.getDuration() +"");
            }else {
                holder.binding.detailLeftItem3.setText(diamondMobile.getNickname());
            }

        }
    }

    @Override
    public int getItemCount() {
        return null == diamondMobileList ? 0 : diamondMobileList.size();
    }


    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemMineDetailBinding binding;
        public ItemViewHolder(@NonNull ItemMineDetailBinding binding) {
            super(binding.getRoot());
            this.binding = binding;

        }
    }
}
